{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "import re\n",
    "def replace(w) :\n",
    "    w = re.sub('&amp;', '\\&',  w)\n",
    "    w = re.sub('&lt;', '<', w)\n",
    "    w = re.sub('&gt;', '>', w)\n",
    "    w = re.sub(r'_', r'\\\\_', w)\n",
    "    w = re.sub(r'%', r'\\\\%', w)\n",
    "    w = re.sub(r'#', r'\\\\#', w)\n",
    "    return w"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "adv_examples_odds_neg\n",
      "1074\n",
      "adv_examples_odds_neg\n",
      "367\n",
      "adv_examples_odds_neg\n",
      "13285\n",
      "adv_examples_odds_neg\n",
      "3018\n",
      "adv_examples_odds_neg\n",
      "adv_examples_pos\n",
      "616\n",
      "adv_examples_pos\n",
      "815\n",
      "adv_examples_pos\n",
      "1256\n",
      "adv_examples_pos\n",
      "4994\n",
      "adv_examples_pos\n",
      "3960\n",
      "adv_examples_neg\n",
      "559\n",
      "adv_examples_neg\n",
      "1270\n",
      "adv_examples_neg\n",
      "1965\n",
      "adv_examples_neg\n",
      "1946\n",
      "adv_examples_neg\n",
      "2099\n",
      "adv_examples_odds_pos_rev\n",
      "1192\n",
      "adv_examples_odds_pos_rev\n",
      "616\n",
      "adv_examples_odds_pos_rev\n",
      "2127\n",
      "adv_examples_odds_pos_rev\n",
      "6300\n",
      "adv_examples_odds_pos_rev\n",
      "428\n",
      "adv_examples_odds_neg_rev\n",
      "432\n",
      "adv_examples_odds_neg_rev\n",
      "555\n",
      "adv_examples_odds_neg_rev\n",
      "888\n",
      "adv_examples_odds_neg_rev\n",
      "1212\n",
      "adv_examples_odds_neg_rev\n",
      "adv_examples_pos_rev\n",
      "772\n",
      "adv_examples_pos_rev\n",
      "564\n",
      "adv_examples_pos_rev\n",
      "2127\n",
      "adv_examples_pos_rev\n",
      "1780\n",
      "adv_examples_pos_rev\n",
      "428\n",
      "adv_examples_odds_pos\n",
      "1512\n",
      "adv_examples_odds_pos\n",
      "843\n",
      "adv_examples_odds_pos\n",
      "1256\n",
      "adv_examples_odds_pos\n",
      "2063\n",
      "adv_examples_odds_pos\n",
      "1005\n",
      "adv_examples_neg_rev\n",
      "302\n",
      "adv_examples_neg_rev\n",
      "462\n",
      "adv_examples_neg_rev\n",
      "1158\n",
      "adv_examples_neg_rev\n",
      "1212\n",
      "adv_examples_neg_rev\n",
      "492\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "def read_to_tex(file) :\n",
    "    df = pd.read_csv(file)\n",
    "    shortest = np.argmin(list(df['sentence'].apply(lambda s : len(s))))\n",
    "    df = df[df.index == shortest]\n",
    "    outputs = []\n",
    "    output = ''\n",
    "    for index, row in df.iterrows():\n",
    "#         if len(row['sentence']) < 3000 :\n",
    "        output += '\\\\textbf{Difference :} ' + row['adv_diff'] + '\\n\\n'\n",
    "#         output += '\\\\textbf{Adversarial :} ' + row['adv'] + '\\n\\n'\n",
    "        output += '\\\\textbf{Original Output : } ' + row['orig_y'] + '\\n\\n'\n",
    "        output += '\\\\textbf{Adversarial Output : } ' + row['adv_y'] + '\\n\\n'\n",
    "        output += '\\\\noindent\\\\rule{\\\\textwidth}{1pt}\\n\\n'\n",
    "        print(len(row['sentence']))\n",
    "    os.makedirs(os.path.join('Workshop-NAACL-Attention', os.path.dirname(file)), exist_ok=True)\n",
    "    f = open(os.path.join('Workshop-NAACL-Attention', file + '.tex'), 'w')\n",
    "    f.write(replace(output))\n",
    "    f.close()\n",
    "\n",
    "datasets = ['mortality', 'readmission', 'KneeSurgery', 'HipSurgery', 'Phenotyping']\n",
    "for d in os.listdir('graph_outputs') :\n",
    "    if d.startswith('adv_examples') :\n",
    "        for e in datasets :\n",
    "            try :\n",
    "                file = os.path.join('graph_outputs', d, e+'+lstm+tanh.csv')\n",
    "                print(d)\n",
    "                read_to_tex(file)\n",
    "            except :\n",
    "                continue"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "metadata": {},
   "outputs": [],
   "source": [
    "text = '''\n",
    "{\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut 8}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{350, 0.00, 1.0}{\\strut :}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut 27}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut am}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut us\\_intr}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut -}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut op}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut 60}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut mins}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut clip}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut \\#}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut reason}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{350, 0.00, 1.0}{\\strut :}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut brain\\_tumor}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut ,}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut ious}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut \\_}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut final\\_report}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut indication}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{350, 0.00, 1.0}{\\strut :}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut solid}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut and}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.02, 1.0}{\\strut cystic}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.04, 1.0}{\\strut brain}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.10, 1.0}{\\strut mass}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut for}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.02, 1.0}{\\strut surgical}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.03, 1.0}{\\strut resection}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut .}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut high}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{350, 0.00, 1.0}{\\strut resolution}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut scans}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut were}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut performed}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut on}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut the}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{350, 0.00, 1.0}{\\strut brain}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut surface}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut of}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut the}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{350, 0.00, 1.0}{\\strut right}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut hemisphere}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut just}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut to}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut the}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{350, 0.00, 1.0}{\\strut right}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut of}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{350, 0.00, 1.0}{\\strut midline}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut ,}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{350, 0.00, 1.0}{\\strut demonstrating}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut a}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut large}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut solid}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut and}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut cystic}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut mass}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut measuring}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{350, 0.00, 1.0}{\\strut approximately}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut 6}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{350, 0.00, 1.0}{\\strut cm}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut in}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{350, 0.00, 1.0}{\\strut diameter}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut and}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut surrounded}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut by}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut an}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut area}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut of}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.11, 1.0}{\\strut chronic}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut echogenic}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut brain}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut edema}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut .}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut the}} \\ldots\\dots {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{350, 0.00, 1.0}{\\strut conclusion}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{350, 0.00, 1.0}{\\strut :}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut large}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut solid}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut and}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.01, 1.0}{\\strut cystic}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.03, 1.0}{\\strut brain}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.08, 1.0}{\\strut mass}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut most}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut compatible}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut with}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut a}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut cystic}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.02, 1.0}{\\strut astrocytoma}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut .}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut post}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut -}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.01, 1.0}{\\strut resection}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut scan}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut showed}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut no}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{350, 0.00, 1.0}{\\strut evidence}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut of}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut residual}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut locules}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut or}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{350, 0.48, 1.0}{\\strut tumor}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut .}}'''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "metadata": {},
   "outputs": [],
   "source": [
    "text = text.replace('\\f', '\\\\f')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'{\\\\setlength{\\\\fboxsep}{0pt}\\\\colorbox[Hsb]{202, 0.00, 1.0}{\\\\strut 8}}'"
      ]
     },
     "execution_count": 103,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import re\n",
    "pat = re.escape('{\\setlength{\\\\fboxsep}{0pt}\\colorbox[Hsb]{') + '\\d+, (\\d\\.\\d+)' + re.escape(', 1.0}{') + '(' + re.escape('\\strut ') + '[^}]*)'+ re.escape('}}')\n",
    "p = re.compile(pat)\n",
    "p.search(text).group()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "metadata": {},
   "outputs": [],
   "source": [
    "import lorem\n",
    "lorem = lorem.text().split()\n",
    "j = 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "metadata": {},
   "outputs": [],
   "source": [
    "def replace(m) :\n",
    "    global j\n",
    "    if float(m.groups()[0]) == 0.0 :\n",
    "        new_word = '\\strut ' + lorem[j]\n",
    "        j += 1\n",
    "        word = m.groups()[1]\n",
    "        return m.group().replace(word, new_word)\n",
    "    else :\n",
    "        word = m.groups()[1]\n",
    "        new_word = '\\\\textbf{' + word  + '}'\n",
    "        return m.group().replace(word, new_word)\n",
    "    return m.group()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 108,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "{\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut sed}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{350, 0.00, 1.0}{\\strut dolore}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut tempora.}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut Numquam}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut etincidunt}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut est}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut quiquia.}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut Eius}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut modi}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut consectetur}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut sed}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut est}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{350, 0.00, 1.0}{\\strut dolore.}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut Labore}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut quiquia}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut numquam}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut aliquam.}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut Non}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut aliquam}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{350, 0.00, 1.0}{\\strut amet}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut non}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut aliquam.}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.02, 1.0}{\\textbf{\\strut cystic}}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.04, 1.0}{\\textbf{\\strut brain}}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.10, 1.0}{\\textbf{\\strut mass}}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut Eius}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.02, 1.0}{\\textbf{\\strut surgical}}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.03, 1.0}{\\textbf{\\strut resection}}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut aliquam}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut porro}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{350, 0.00, 1.0}{\\strut quaerat}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut quiquia}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut adipisci}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut velit.}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut Numquam}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut quiquia}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{350, 0.00, 1.0}{\\strut etincidunt}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut dolorem.}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut Consectetur}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut sed}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{350, 0.00, 1.0}{\\strut sit}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut adipisci}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut dolor}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut dolore.}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut Eius}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{350, 0.00, 1.0}{\\strut quisquam}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut aliquam}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{350, 0.00, 1.0}{\\strut sed}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut ipsum}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{350, 0.00, 1.0}{\\strut adipisci}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut sit}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut est.}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut Consectetur}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut modi}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut non}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut eius.}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut Ut}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{350, 0.00, 1.0}{\\strut ipsum}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut quaerat}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{350, 0.00, 1.0}{\\strut tempora.}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut Etincidunt}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{350, 0.00, 1.0}{\\strut ipsum}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut neque}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut dolor}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut est.}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut Consectetur}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut dolore}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut amet}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.11, 1.0}{\\textbf{\\strut chronic}}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut dolore}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut modi}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut quaerat.}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut Eius}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut aliquam}} \\ldots\\dots {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{350, 0.00, 1.0}{\\strut dolore}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{350, 0.00, 1.0}{\\strut adipisci.}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut Labore}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut etincidunt}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut quisquam}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.01, 1.0}{\\textbf{\\strut cystic}}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.03, 1.0}{\\textbf{\\strut brain}}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.08, 1.0}{\\textbf{\\strut mass}}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut magnam}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut consectetur.}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut Ut}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut dolor}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut adipisci}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.02, 1.0}{\\textbf{\\strut astrocytoma}}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut non}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut quaerat.}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut Quiquia}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.01, 1.0}{\\textbf{\\strut resection}}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut quiquia}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut dolorem}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut velit.}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{350, 0.00, 1.0}{\\strut Eius}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut neque}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut consectetur}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut etincidunt}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut voluptatem}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{350, 0.48, 1.0}{\\textbf{\\strut tumor}}} {\\setlength{\\fboxsep}{0pt}\\colorbox[Hsb]{202, 0.00, 1.0}{\\strut labore.}}\n"
     ]
    }
   ],
   "source": [
    "print(p.sub(lambda m : replace(m), text))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'\\\\{\\\\\\\\setlength\\\\{\\\\\\x0cboxsep\\\\}\\\\{0pt\\\\}\\\\\\\\colorbox\\\\[Hsb\\\\]\\\\{350,\\\\ \\\\d\\\\.\\\\d+,\\\\ 1\\\\.0\\\\}\\\\{\\\\\\\\strut\\\\ \\\\.\\\\*\\\\}\\\\}'"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pat"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
